import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import NotFoundView from '../views/NotFoundView.vue'
import LoginView from '../views/LoginView.vue'
import PropertyFeeView from '../views/PropertyFeeView.vue'
import HouseView from '../views/HouseView.vue'
import SettingView from '../views/SettingView.vue'
import FyyHouse from '../views/FyyHouse.vue'
import FyyOwner from '../views/FyyOwner.vue'
import FyyOwner11 from '../views/FyyOwner11.vue'
import ownerList from '../views/ownerList.vue'
// import ExamplesLayout from '../views/examples/ExamplesLayout.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: HomeView,
      meta: { 
        title: '首页',
        icon: 'Odometer',
        showInMenu: true,
        order: 1
      }
    },
    {
      path: '/house',
      name: 'house',
      component: HouseView,
      meta: { 
        title: '房屋信息',
        icon: 'House',
        showInMenu: true,
        order: 2
      }
    },
/*     {
      path: '/property-fee',
      name: 'propertyFee',
      component: PropertyFeeView,
      meta: { 
        title: '物业费',
        icon: 'Money',
        showInMenu: true,
        order: 3
      }
    }, */
    {
      path: '/ownerList copy',
      name: 'ownerList copy',
      component: HouseView,
      meta: { 
        title: '物业费',
        icon: 'Money',
        showInMenu: true,
        order: 3
      }
    },    
    {
      path: '/repair',
      name: 'repair',
      component: NotFoundView,
      meta: { 
        title: '报修管理',
        icon: 'Service',
        showInMenu: true,
        order: 4
      }
    },
    {
      path: '/fyyOwner',
      name: 'fyyOwner',
      component: NotFoundView,
      meta: { 
        title: '公告查看',
        icon: 'Bell',
        showInMenu: true,
        order: 5
      }
    },
    {
      path: '/ownerList',
      name: 'ownerList',
      component: ownerList,
      meta: { 
        title: '业主管理',
        icon: 'User',
        adminOnly: true,
        showInMenu: true,
        order: 6
      }
    },
    {
      path: '/fyyOwner',
      name: 'fyyOwner',
      component: () => import('@/views/FyyOwner.vue'), // 检查组件路径
      props: true // 允许通过props接收路由参数
    },    
        {
      path: '/FyyHouse',
      name: 'FyyHouse',
      component: FyyHouse,
      meta: { 
        title: '房屋管理',
        icon: 'House',
        adminOnly: true,
        showInMenu: true,
        order: 6
      }
    },
    {
      path: '/setting',
      name: 'setting',
      // component: ExamplesLayout,
      redirect: '/setting/theme',
      meta: { 
        title: '系统设置',
        icon: 'Setting',
        adminOnly: true,
        showInMenu: true,
        order: 7
      },
      children: [
        {
          path: 'user',
          name: 'userSetting',
          component: NotFoundView,
          meta: {
            title: '用户设置',
            icon: 'User',
            showInMenu: true
          }
        },
        {
          path: 'system',
          name: 'systemSetting',
          component: NotFoundView,
          meta: {
            title: '系统参数',
            icon: 'Setting',
            showInMenu: true
          }
        },
        {
          path: 'theme',
          name: 'themeSetting',
          component: SettingView,
          meta: {
            title: '主题设置',
            icon: 'Brush',
            showInMenu: true
          }
        }
      ]
    },
    {
      path: '/login',
      name: 'login',
      component: LoginView,
      meta: { 
        title: '登录',
        showInMenu: false
      }
    },
    {
      path: '/examples',
      // component: ExamplesLayout,
      // redirect: '/examples',
      redirect: '/examples/table',
      meta: {
        title: '组件示例',
        icon: 'Compass',
        showInMenu: true,
        order: 8
      },
      children: [

        {
          path: 'table',
          name: 'table-example',
          component: () => import('../views/examples/TableExample.vue'),
          meta: {
            title: '表格示例',
            icon: 'Grid',
            showInMenu: true
          }
        },
        {
          path: 'form',
          name: 'form-example',
          component: () => import('../views/examples/FormExample.vue'),
          meta: {
            title: '表单示例',
            icon: 'List',
            showInMenu: true
          }
        },
        
        {
          path: 'card',
          name: 'card-example',
          component: () => import('../views/examples/CardExampleView.vue'),
          meta: {
            title: '卡片示例',
            icon: 'Document',
            showInMenu: true
          }
        },
        {
          path: 'notification',
          name: 'notification-example',
          component: () => import('../views/examples/NotificationExampleView.vue'),
          meta: {
            title: '消息通知示例',
            icon: 'Bell',
            showInMenu: true
          }
        },
        {
          path: 'charts',
          name: 'charts-example',
          component: () => import('../views/examples/ChartsExample.vue'),
          meta: {
            title: '图表示例',
            icon: 'PieChart',
            showInMenu: true
          }
        },
        {
          path: 'upload',
          name: 'upload-example',
          component: () => import('../views/examples/UploadExample.vue'),
          meta: {
            title: '上传示例',
            icon: 'Upload',
            showInMenu: true
          }
        },
        {
          path: 'editor',
          name: 'editor-example',
          component: () => import('../views/examples/EditorExample.vue'),
          meta: {
            title: '富文本编辑器',
            icon: 'Edit',
            showInMenu: true
          }
        }
      ]
    },
    {
      path: '/:pathMatch(.*)*',
      name: 'notFound',
      component: NotFoundView,
      meta: { 
        title: '页面未找到',
        showInMenu: false
      }
    }
  ]
})

// 全局前置守卫
router.beforeEach((to, from, next) => {
  // 设置页面标题
  document.title = to.meta.title ? `${to.meta.title} - 住宅管理系统` : '住宅管理系统'
  next()
})

export default router
